<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            width: 500px;
            height: 400px;
            background-color: black;
            margin: 50px auto;
        }

        ul li {
            width: 100%;
            height: 50%;
            display: flex;
            flex-direction: row;
            justify-content: space-around;
            color: white;
            font-weight: bold;
            font-size: 40px;
            line-height: 200px;
        }

        ul li span {
            width: 100px;
            height: 100px;
            background-color: red;
            color: yellow;
            font-weight: bold;
            font-size: 36px;
            text-align: center;
            line-height: 100px;
        }
    </style>
</head>

<body>
    <ul>
        <li>京东秒杀倒计时</li>
        <li>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </li>
    </ul>
</body>

</html>
<script>
    //获取元素
    let span = document.querySelectorAll('span')
    //函数中封装
    function fun() {
        let ing = +new Date()
        let future = +new Date('2022/11/1')
        let gap = future - ing
        // console.log(gap);
        let day = parseInt(gap / 1000 / 60 / 60 / 24)  //天
        let dayVal = day < 10 ? '0' + day : day;
        span[0].innerHTML = dayVal + '天';
        let time = parseInt(gap / 1000 / 60 / 60 % 24)  //时
        let timeVal = time < 10 ? '0' + time : time;
        span[1].innerHTML = timeVal + '时';
        let met = parseInt(gap / 1000 / 60 % 60)  //分
        let metVal = met < 10 ? '0' + met : met;
        span[2].innerHTML = metVal + '分';
        let mou = parseInt(gap / 1000 % 60)  //秒
        let mouVal = mou < 10 ? '0' + mou : mou;
        span[3].innerHTML = mouVal + '秒';

    }
    setInterval(()=>{
        fun()
    })
</script>